package com.iedu.demo.lgq.mapper;

import com.iedu.demo.lgq.entity.TbOrderItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderItemMapper {

    // 保存订单商品
    @Insert("INSERT INTO tb_order_item(id, item_id, order_id, num, title, price, total_fee, pic_path) " +
            "VALUES(#{id}, #{itemId}, #{orderId}, #{num}, #{title}, #{price}, #{totalFee}, #{picPath})")
    void saveOrderItem(TbOrderItem orderItem);

    // 根据订单ID查询订单商品
    @Select("SELECT * FROM tb_order_item WHERE order_id = #{orderId}")
    List<TbOrderItem> getOrderItemsByOrderId(String orderId);

    // 批量删除订单商品
    @Delete("<script>" +
            "DELETE FROM tb_order_item WHERE order_id IN " +
            "<foreach collection='orderIds' item='orderId' open='(' separator=',' close=')'>" +
            "#{orderId}" +
            "</foreach>" +
            "</script>")
    void deleteOrderItemsByOrderIds(@Param("orderIds") List<String> orderIds);
}
